package com.gsafety.wellsfort.controller.knowledge;

import com.gsafety.wellsfort.common.util.ApiResponse;
import com.gsafety.wellsfort.domain.dto.ids.WorkIdDTO;
import com.gsafety.wellsfort.domain.dto.work.*;
import com.gsafety.wellsfort.domain.vo.QuestionVO;
import com.gsafety.wellsfort.domain.vo.WorkVO;
import com.gsafety.wellsfort.service.knowledge.WorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "作业管理",description = "作业管理接口")
@RestController
@Slf4j
@RequestMapping("/api/work")
public class WorkController {
    @Autowired
    private WorkService workService;
    @ApiOperation(value="保存作业基本信息")
    @PostMapping("/save-baseinfo")
    public ApiResponse<WorkBaseInfoDTO> saveBaseInfo(@RequestBody WorkBaseInfoDTO workBaseInfoDTO){
        return workService.saveBaseInfo(workBaseInfoDTO);
    }
    @ApiOperation(value="保存作业配置信息")
    @PostMapping("/save-worksetting")
    public ApiResponse<WorkSettingDTO> saveBaseInfo(@RequestBody WorkSettingDTO workSettingDTO){
        return workService.saveWorkSetting(workSettingDTO);
    }
    @ApiOperation(value="从作业中移除一道试题")
    @PostMapping("/remove-question")
    public ApiResponse removeQuestion(@RequestBody WorkIdDTO idDTO){
        return workService.removeQuestion(idDTO.getWorkQuId());
    }

    @ApiOperation(value="给作业添加试题")
    @PostMapping("/add-question")
    public ApiResponse<WorkQuDTO> addQuestion(@RequestBody WorkQuDTO workQuDTO){
        return workService.addQuestion(workQuDTO);
    }

    @ApiOperation(value="编辑预览作业")
    @PostMapping("/get-work")
    public ApiResponse<WorkVO> getWork(@RequestBody WorkIdDTO idDTO){
        return workService.getWork(idDTO.getWorkId());
    }
    @ApiOperation(value="查询作业列表")
    @PostMapping("/work-list")
    public ApiResponse<List<WorkVO>> findWorkByPageParams(@RequestBody WorkQueryDTO workQuDtoParams){
        return workService.findWorkByPageParams(workQuDtoParams);
    }
    @ApiOperation(value="根据类型分页获取作业题目列表")
    @PostMapping("/workQu-list")
    public ApiResponse<List<QuestionVO>> findQuestionByPageParams(@RequestBody WorkQuQueryDTO workQuDtoParams){
        return workService.findQuestionByPageParams(workQuDtoParams);
    }
    @ApiOperation(value="未添加到作业里的题目列表")
    @PostMapping("/addQu-list")
    public ApiResponse<List<QuestionVO>> findAddQuestionByPageParams(@RequestBody WorkQuQueryDTO workQuDtoParams){
        return workService.findAddQuestionByParam(workQuDtoParams);
    }

    @ApiOperation(value="删除作业")
    @PostMapping("/del-work")
    public ApiResponse deleteWork(@RequestBody WorkIdDTO idDTO){
        return workService.deleteWork(idDTO.getWorkId());
    }

}
